<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Title</title>
</head>
<body>

</body>
<script>
	function light(color){
		return new Promise((resolve) => {
			setTimeout(() => {
				console.log(color)
				resolve()
			},2000)
		})
	}
	async function run(color){
		await light(color)
	}
	async function cycle(){
		let colors = ['红灯','黄灯','绿灯']
		let index = 0
		while (true){
			await run(colors[index % 3])
			index++
		}
	}
	cycle()
</script>
</html>